/*
 * filter.h
 *
 *  Created on: Dec 14, 2024
 *      Author: zxx
 */

#ifndef INC_FILTER_H_
#define INC_FILTER_H_
#include "main.h"

//放大2^14
#define ADC_SERVICE_BUS_VOLTAGE_BAND_GAP_50HZ_A1    (-32223)
#define ADC_SERVICE_BUS_VOLTAGE_BAND_GAP_50HZ_A2    (15856)
#define ADC_SERVICE_BUS_VOLTAGE_BAND_GAP_50HZ_B0    (14746)//0.9
#define ADC_SERVICE_BUS_VOLTAGE_BAND_GAP_50HZ_B1    (-32750)
#define ADC_SERVICE_BUS_VOLTAGE_BAND_GAP_50HZ_B2    (16384)


#define Limit_EN  0
void Filter_Init();


typedef struct filter1{

	int16_t s16Input;
	int16_t s16InputUpperLimit;
	int16_t s16InputLowerLimit;
	int32_t s32A1;
	int32_t s32A2;
	int64_t s64X1;
	int64_t s64X2;
	int16_t s16Output;
	int16_t s16OutputUpperLimit;
	int16_t s16OutputLowerLimit;
	int32_t s32B0;
	int32_t s32B1;
	int32_t s32B2;


}Control_Driver_SecondOrderIirfpLoop_t;


typedef struct FirstOrderFilter
{
    int16_t s16Ka;
    int16_t s16InputLast;
    int16_t s16OutputLast;

    int16_t s16OutputUpperLimit;
    int16_t s16OutputLowerLimit;

    int16_t s16Input;
    int16_t s16Output;

}Control_Driver_FirstOrderFilter_t;


extern Control_Driver_SecondOrderIirfpLoop_t bus_filter_out;
extern Control_Driver_FirstOrderFilter_t bus_filter_out1;

int16_t Control_Driver_FirstOrderApf(Control_Driver_FirstOrderFilter_t *tFirstOrderApf, uint16_t u16MathQ);

int16_t Control_Driver_SecondOrderIirfp(Control_Driver_SecondOrderIirfpLoop_t *tSecondOrderIirfpLoop, uint16_t u16MathQ);
#endif /* INC_FILTER_H_ */
